// sharedFreightData.js
import { defineStore } from 'pinia'
export const commonHeaderDefinitions = {
    id: { text: '', cellType: 'cellText', width: '0px' },
    startPort: { text: '起运港', cellType: 'cellTextButton', width: '100px' },
    endPort: { text: '目的港', cellType: 'cellTextButton', width: '100px' },
    triangleTrade: { text: '三角贸易', cellType: 'cellCheckbox' },
    transitPort: { text: '中转港', cellType: 'cellTextButton', width: '100px' },
    transportMode: {
        text: '运输方式',
        cellType: 'cellCombobox',
        width: '100px',
        comboxlist: {
            field: 'code;name',
            displayname: 'name',
            returndata: 'code',
            data: [
                { code: '111', name: '111name' },
                { code: '222', name: '222name' }
            ]
        }
    },
    currency: { text: '币种', cellType: 'cellTextButton', width: '80px' },
    carrier: {
        text: '承运人',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbid;dbdatauser',
            sourceField: 'dbid;dbdatauser',
            destField: 'carrier;carrierCode',
            showField: 'dbdatauser;posid;dbid',

            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    carrierCode: { text: '承运人代码', cellType: 'cellText' },

    containerGrade: { text: '集装箱等级', cellType: 'cellCheckbox' },
    serviceLiver: {
        text: '服务级别',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'serviceLiver',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    carrierLevel: { text: '承运人级别', cellType: 'advancedCellTextButton', width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'serviceLiver',
            showField: 'dbdatauser;posid;dbid',

            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        } },
    product: {
        text: '商品',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'product',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    commLocal: { text: 'Comm.Local', cellType: 'cellText' },
    controlCustomer: {
        text: '控制客户',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'controlCustomer',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    shipper: {
        text: '发货人',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'shipper',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    consignee: {
        text: '收货人',
        cellType: 'advancedCellTextButton',
        width: '100px',
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser',
            sourceField: 'dbdatauser',
            destField: 'consignee',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    unit: { text: '单位', cellType: 'cellText' },
    transportTime: {
        text: '运输时间',
        cellType: 'cellCombobox',
        width: '100px',
        comboxlist: {
            field: 'code;name',
            displayname: 'name',
            returndata: 'code',
            data: [
                {"code": "SMD", "name": "同日"},
                {"code": "OVN", "name": "隔夜"},
                {"code": "1", "name": "1天"},
                {"code": "2", "name": "2天"},
                {"code": "3", "name": "3天"}
            ]
        }
    },
    frequency: { text: '频率', cellType: 'cellText' },
    frequencyUnit: {
        text: '频率单位',
        cellType: 'cellCombobox',
        width: '100px',
        comboxlist: {
            field: 'code;name',
            displayname: 'name',
            returndata: 'frequencyUnit',
            data: [
                {"code": "Daily", "name": "1 per day"},
                {"code": "Weekly", "name": "Every X days"},
                {"code": "Fortnightly", "name": "X per fortnight"},
                {"code": "Monthly", "name": "X per month"},
                {"code": "Weekly", "name": "X per week"}
            ]
        }
    },
    startDate: { text: '开始日期', cellType: 'cellDate' },
    expiryDate: { text: '到期日期', cellType: 'cellDate' },
    customerContractNo: { text: '客户合约号', cellType: 'cellText' },
    contractLink: { text: '链接合约', cellType: 'cellText' },
    contractNo: { text: '约号', cellType: 'cellText' },
    publish: { text: '发布', cellType: 'cellCheckbox' }
};

export function getCommonHeader(field) {
    return commonHeaderDefinitions[field] || null;
}
export const commonFeeHeaders = [
    {
        field: "costCode",
        text: "费用代码",
        cellType: "advancedCellTextButton",
        searchObj: {
            url: 'http://gxmengshiqiye.net/jeecg-boot/dbsystem/dbuserandzd/list?bestop=0',
            keyField: 'dbdatauser,posid',
            sourceField: 'posid;dbdatauser',
            destField: 'costCode;description',
            showField: 'dbdatauser;posid;dbid',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjUyNDMxNjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.LOH1viCiq2sgo2Z5g_zP8jXpKl1qyBvThy9MGj6KYIA'
        }
    },
    { field: "description", text: "说明", cellType: "cellText" },
    { field: "localDescription", text: "本地说明", cellType: "cellText" },
    { field: "unit", text: "单位", cellType: "cellCombobox", comboxlist: {
            field: 'code;name',
            displayname: 'name',
            returndata: 'unit',
            data: [
                {"code": "KG", "name": "KG"},
                {"code": "TEU", "name": "TEU"}
            ]
        } },
    { field: "tableFormula", text: "表达式说明", cellType: "cellText" },
    { field: "condition", text: "条件", cellType: "cellText" },
    { field: "rateDescription", text: "改写说明", cellType: "cellText" },
    { field: "tableType", text: "表达式", cellType: "cellText" },
    { field: "minAmount", text: "倍数", cellType: "cellText" },
    { field: "actualWeightVolume", text: "实际重量/体积", cellType: "cellDecimal" },
    { field: "unitQuantity", text: "单位/适数", cellType: "cellText" },
    { field: "workingType", text: "工作类型", cellType: "cellText" },
    { field: "containerType", text: "箱主类型", cellType: "cellText" }
];

export const getCommonTableData = () => [
    {
        startPort: 'Shanghai',
        endPort: 'Los Angeles',
        triangleTrade: 'No',
        transitPort: 'N/A',
        transportMode: 'Sea',
        currency: 'USD',
        carrier: 'COSCO',
        carrierCode: 'COSU',
        containerGrade: 'Standard',
        shipType: 'Container Ship',
        carrierBrand: 'COSCO Shipping',
        commLocal: 'Local',
        receivedFromCustomer: '2023-08-15',
        shipper: 'ABC Electronics Co., Ltd.',
        consignee: 'XYZ Distribution Inc.',
        unit: 'TEU',
        transportTime: '18',
        frequency: '2',
        frequencyUnit: 'Weekly',
        startDate: '2023-09-01',
        expiryDate: '2024-08-31',
        customerContractNo: 'CUST-2023-001',
        bookingNo: 'BKG-12345',
        release: 'Released',
        serviceCode: 'TPX',
        fmcTid: 'FMC-123456'
    },
    {
        startPort: 'Hamburg',
        endPort: 'New York',
        triangleTrade: 'Yes',
        transitPort: 'Rotterdam',
        transportMode: 'Sea',
        currency: 'EUR',
        carrier: 'Maersk',
        carrierCode: 'MAEU',
        containerGrade: 'Refrigerated',
        shipType: 'Container Ship',
        carrierBrand: 'Maersk Line',
        commLocal: 'International',
        receivedFromCustomer: '2023-08-20',
        shipper: 'German Auto Parts GmbH',
        consignee: 'American Motors Corp.',
        unit: 'FEU',
        transportTime: '12',
        frequency: '1',
        frequencyUnit: 'Weekly',
        startDate: '2023-09-15',
        expiryDate: '2024-09-14',
        customerContractNo: 'CUST-2023-002',
        bookingNo: 'BKG-67890',
        release: 'Pending',
        serviceCode: 'TA3',
        fmcTid: 'FMC-789012'
    }
];

export const getCommonFeeData = () => [
    {
        costCode: 'CODE001',
        description: '空运示例说明1',
        unit: 'KG',
    },
    {
        costCode: 'CODE002',
        description: '海运示例说明1',
        unit: 'TEU',
    }
];


export const getCalculatorData = () => [

    {"code": "AGY", "name": "代理计算器"},
    {"code": "CMB", "name": "净值价证券单位保本率_最低_最高收费计算器"},
    {"code": "CNG", "name": "以成本_准貼现计算器"},
    {"code": "CTC", "name": "以'公司價目表'式建的计算器"},
    {"code": "CTG", "name": "运输计算器"},
    {"code": "CTZ", "name": "以运输区域距离为基础的计算器"},
    {"code": "EXL", "name": "不用于公司价目表的计算器"},
    {"code": "FCC", "name": "固定费率计算器"},
    {"code": "FLI", "name": "固定费率计算器"},
    {"code": "FPU", "name": "固定费用计算器"},
    {"code": "HCC", "name": "最高收费计算器"},
    {"code": "HRC", "name": "最高价格计算器"},
    {"code": "IAT", "name": "件数计算器"},
    {"code": "FRT", "name": "含运费计算器"},
    {"code": "IXC", "name": "价格计算器"},
    {"code": "MIN", "name": "最低定额计算器"},
    {"code": "MPU", "name": "最低主观收费单位价格计算器"},
    {"code": "NTE", "name": "自由文本计算器"},
    {"code": "HRT", "name": "分单价计算方式计算器"},
    {"code": "PER", "name": "百分比计算器"},
    {"code": "PEB", "name": "百分比分段计算器"},
    {"code": "PSR", "name": "利润分成/回扣计算器"},
    {"code": "SMB", "name": "每月分段收费计算器"},
    {"code": "UNT", "name": "单位计算器"},
    {"code": "TME", "name": "时间计算器"},
    {"code": "DIN", "name": "代收代付和息计算器"},
    {"code": "VED", "name": "价格差价和付款计算器"},
    {"code": "WPK", "name": "仓储包装计算器"},
    {"code": "WLT", "name": "仓储位置计算器"}

];


export const useFreightForwarderStore = defineStore('freightForwarder', {
    state: () => ({
        freightForwarderData: {
            business: []
        }
    }),
    actions: {


        setFreightForwarderData(newData) {
            this.freightForwarderData = newData;
        },
        updateBusiness(newData) {
            const index = this.freightForwarderData.business.findIndex(b => b.id === newData.id)
            if (index !== -1) {
                this.freightForwarderData.business[index] = { ...this.freightForwarderData.business[index], ...newData }
            } else {
                this.freightForwarderData.business.push(newData)
            }
        },
        updateFeeTable(businessId, newFeeData) {
            const business = this.freightForwarderData.business.find(b => b.id === businessId)
            if (business) {
                if (!business.feeTable) {
                    business.feeTable = []
                }
                const feeIndex = business.feeTable.findIndex(fee => fee.id === newFeeData.id)
                if (feeIndex !== -1) {
                    business.feeTable[feeIndex] = { ...business.feeTable[feeIndex], ...newFeeData }
                } else {
                    business.feeTable.push(newFeeData)
                }
            }
        }
    },
    getters: {
        getBusinessByType: (state) => (businessType) => {
            return state.freightForwarderData.business.find(b => b.businessType === businessType) || {}
        }
    }
})
